import {
	UPLOADURL
} from "./config.js"
const upload = (filePath, data = {}) => {

	return new Promise((resolve, reject) => {

		uni.uploadFile({
			url: UPLOADURL, //仅为示例，非真实的接口地址
			filePath: filePath,
			name: 'file',
			formData: data,
			header: {
			    'Authorization': uni.getStorageSync("token")  //自定义请求头信息
			},
			success: (uploadFileRes) => {

				resolve(JSON.parse(uploadFileRes.data))
				console.log(uploadFileRes.data);
			},
			fail: (error) => {

				reject(error)
			}
		});

	})

}
const chooseImage = count => {

 return	new Promise((resolve, reject) => {

		uni.chooseImage({
			count: count, //默认9
			sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
			sourceType: ['album', 'camera'], //从相册选择
			success: function(res) {

				resolve(res.tempFilePaths);

				console.log(9999, JSON.stringify(res.tempFilePaths));
			},
			fail: (error) => {
				reject(error)
			}
		});

	})



}
export {
	upload,
	chooseImage
}
